package com.mcxx.modules.miniSalvation.order.service.read;

import com.mcxx.common.exception.BizException;
import com.mcxx.modules.BaseParam;
import com.mcxx.modules.base.service.read.AreaHelper;
import com.mcxx.modules.base.utils.QueryParamUtil;
import com.mcxx.modules.miniSalvation.check.dto.CheckFamilyDTO;
import com.mcxx.modules.miniSalvation.check.dto.IntegrateCheckDTO;
import com.mcxx.modules.miniSalvation.check.dto.ProResultDTO;
import com.mcxx.modules.miniSalvation.check.dto.QueryCheckDTO;
import com.mcxx.modules.miniSalvation.check.service.read.CheckReadService;
import com.mcxx.modules.miniSalvation.family.dto.*;
import com.mcxx.modules.miniSalvation.family.param.ProvertyObjectParam;
import com.mcxx.modules.miniSalvation.family.param.SalvationFamilyParam;
import com.mcxx.modules.miniSalvation.family.param.SalvationObjectParam;
import com.mcxx.modules.miniSalvation.order.dao.read.OrderReadDao;
import com.mcxx.modules.miniSalvation.order.dto.*;
import com.mcxx.modules.miniSalvation.order.entity.OrderEntity;
import com.mcxx.modules.miniSalvation.order.param.MoveAreaParam;
import com.mcxx.modules.miniSalvation.order.param.OrderListSearchParam;
import com.mcxx.modules.miniSalvation.order.param.RecheckOrderQueryParam;
import com.mcxx.modules.miniSalvation.order.param.RecheckParam;
import com.mcxx.modules.nopage.dto.MiniSalvationEFileYHDTO;
import com.mcxx.modules.system.dto.AuditConfirmListDTO;
import com.mcxx.modules.system.dto.PdfApproveDTO;
import com.mcxx.modules.system.dto.PdfApproveDetailDTO;
import com.mcxx.util.CommonUtil;
import com.mcxx.util.Constant;
import com.mcxx.util.DateUtil;
import com.mcxx.util.FailureCode;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service("orderReadService")
@TaTransactional(readOnly = true)
public class OrderReadService extends BaseService {
    private static final Logger logger = LoggerFactory.getLogger(OrderReadService.class);
    @Autowired
    private OrderReadDao orderReadDao;
    @Autowired
    private CheckReadService checkReadService;
    @Autowired
    private StandardReadService standardReadService;
    @Autowired
    private AreaHelper areaHelper;


    public Page<OrderSimpleDTO> querySelectRecheckFamily (OrderListSearchParam param, PageParam pageParam,UserAccountVo accountVo){

        QueryParamUtil.setBaseParamValue(param,accountVo);


        orderReadDao.beginPager(pageParam);
        List< OrderSimpleDTO> list = orderReadDao.querySelectRecheckFamily(param);


        return orderReadDao.endPager(list);
    }


    public Page<OrderSimpleDTO> queryRecheckFamily (OrderListSearchParam param, PageParam pageParam,UserAccountVo accountVo){

        QueryParamUtil.setBaseParamValue(param,accountVo);


        orderReadDao.beginPager(pageParam);
        List< OrderSimpleDTO> list = orderReadDao.queryRecheckFamily(param);


        return orderReadDao.endPager(list);
    }


    public Page getTownSalvationTodoList(OrderListSearchParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);


        orderReadDao.beginPager(pageParam);
        List<OrderListDTO> list = orderReadDao.getTownSalvationTodoList(param);


        return orderReadDao.endPager(list);
    }


    public Page getApplyTodoList(OrderListSearchParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);


        orderReadDao.beginPager(pageParam);
        List<OrderListDTO> list = orderReadDao.getApplyTodoList(param);


        return orderReadDao.endPager(list);
    }


    public Page getApplyTodoListByCountry(OrderListSearchParam param, PageParam pageParam) {

        orderReadDao.beginPager(pageParam);
        List<OrderListDTO> list = orderReadDao.getApplyTodoList(param);


        return orderReadDao.endPager(list);
    }


    public Page getNoFinishOrderCounty(OrderListSearchParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);




        orderReadDao.beginPager(pageParam);
        List<OrderListDTO> list = orderReadDao.queryNoFinishOrderCounty(param);


        return orderReadDao.endPager(list);
    }


    public Page listFinishedOrderTown(OrderListSearchParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);


        orderReadDao.beginPager(pageParam);
        List<OrderListDTO> list = orderReadDao.listFinishedOrderTown(param);


        return orderReadDao.endPager(list);
    }


    public Page listFinishedOrderCounty(OrderListSearchParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);


        orderReadDao.beginPager(pageParam);
        List<OrderListDTO> list = orderReadDao.listFinishedOrderCounty(param);


        return orderReadDao.endPager(list);
    }

    public OrderEntity getOrderById(String orderId) {
        return orderReadDao.getOrderById(orderId);
    }


    public List<OrderEntity> queryOrderByIds(String[] ids) {
        return orderReadDao.queryOrderByIds(ids);
    }


    public Page listRecheckFamily(RecheckOrderQueryParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);

        param.setRescueYears(DateUtil.getMonthString());


        orderReadDao.beginPager(pageParam);
        List<OrderListDTO> list = orderReadDao.listRecheckFamily(param);


        return orderReadDao.endPager(list);
    }


    public OrderListDTO getRecheckFamilyCount(RecheckOrderQueryParam param, UserAccountVo accountVo){

        QueryParamUtil.setBaseParamValue(param,accountVo);

        param.setRescueYears(DateUtil.getMonthString());
        return orderReadDao.getRecheckFamilyCount(param);
    }


    public Page getTownRecheckTodoList(RecheckOrderQueryParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);


        orderReadDao.beginPager(pageParam);
        List<OrderListDTO> list = orderReadDao.getTownRecheckTodoList(param);


        return orderReadDao.endPager(list);
    }


    public Page getCountyRecheckTodoList(RecheckOrderQueryParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);


        orderReadDao.beginPager(pageParam);
        List<OrderListDTO> list = orderReadDao.getCountRecheckTodoList(param);


        return orderReadDao.endPager(list);
    }

    public List<RechckToDoOrderListExcelDTO> exportCountRecheckTodoList(RecheckOrderQueryParam param, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);

        List<RechckToDoOrderListExcelDTO> list = orderReadDao.exportCountRecheckTodoList(param);


        return list;
    }


    public String getIdBySourceId(String orderId) {
        return orderReadDao.getIdBySourceId(orderId);
    }


    public String getDataBySourceId(String orderId) {
        return orderReadDao.getDataBySourceId(orderId);
    }


    public OrderDTO getStateAndVersion(String orderId){
        return orderReadDao.getStateAndVersion(orderId);
    }


    public List<OrderDTO> getStateAndVersions(List<String> orderIdList){
        return orderReadDao.getStateAndVersions(orderIdList);
    }


    public List<OrderDTO> getCanSendCheckOrder(List<String> orderIdList, String preBizState, String notEqBizState){
        return orderReadDao.getCanSendCheckOrder(orderIdList, preBizState, notEqBizState);
    }


    public Page listRecheckResult(RecheckParam param, PageParam pageParam,UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param, accountVo);

        param.setNowMonth(com.mcxx.util.DateUtil.getMonthString());


        orderReadDao.beginPager(pageParam);
        List<OrderSimpleDTO> list = orderReadDao.listRecheckResult(param);


        return orderReadDao.endPager(list);
    }

    public List<OrderSimpleExcelDTO> exportRecheckResultList(RecheckParam param, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param, accountVo);

        param.setNowMonth(DateUtil.getMonthString());

        List<OrderSimpleExcelDTO> list = orderReadDao.exportRecheckResult(param);
        return list;
    }


    public List<RechckToDoOrderListExcelDTO> exportRecheckToDoList(RecheckOrderQueryParam param, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);

        List<RechckToDoOrderListExcelDTO> list = orderReadDao.exportTownRecheckTodoList(param);


        return list;
    }


    public int cntByOrderAndBizState(String orderId, String bizState){
        return orderReadDao.cntByOrderAndBizState(orderId, bizState);
    }


    public Page<SalvationFamilyDTO> getSalvationFamilyList(SalvationFamilyParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);
        if (CommonUtil.invalidArgs(param.getSendMonth())) {
            param.setSendMonth(DateUtil.getMonthString());
        }


        orderReadDao.beginPager(pageParam);
        List<SalvationFamilyDTO> list = orderReadDao.getSalvationFamilyList(param);


        return orderReadDao.endPager(list);
    }


    public Page<SalvationFamilyDTO> getMigrationList(MoveAreaParam param, PageParam pageParam, UserAccountVo userAccountVo) {

        QueryParamUtil.setBaseParamValue(param, userAccountVo);


        orderReadDao.beginPager(pageParam);
        List<SalvationFamilyDTO> list = orderReadDao.getAreaMoveFamilyList(param);


        return orderReadDao.endPager(list);
    }

    public List<SalvationFamilyExcelDTO> exportMigrationList(MoveAreaParam param, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);

        List<SalvationFamilyExcelDTO> list = orderReadDao.exportAreaMoveFamilyList(param);

        return list;
    }

    public Page<SalvationObjectDTO> getSalvationObjectList(SalvationObjectParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);
        if(CommonUtil.invalidArgs(param.getSendMonth())){
            param.setSendMonth(DateUtil.getMonthString());
        }

        orderReadDao.beginPager(pageParam);
        List<SalvationObjectDTO> list = orderReadDao.getSalvationObjectList(param);


        return orderReadDao.endPager(list);
    }


    public Page<ProvertyObjectDTO> getProvertyObjectList(ProvertyObjectParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);

        param.setSystemTime(DateUtil.getMonthString());

        orderReadDao.beginPager(pageParam);
        List<ProvertyObjectDTO> list = orderReadDao.getProvertyObjectList(param);


        return orderReadDao.endPager(list);
    }


    public Page<SalvationFamilyDTO> getSupplyFamilyList(SalvationFamilyParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);
        if (CommonUtil.invalidArgs(param.getSendMonth())) {
            param.setSendMonth(DateUtil.getMonthString());
        }


        orderReadDao.beginPager(pageParam);
        List<SalvationFamilyDTO> list = orderReadDao.getSupplyFamilyList(param);


        return orderReadDao.endPager(list);
    }


    public Page<SalvationObjectDTO> getSupplyObjectList(SalvationObjectParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);
        if (CommonUtil.invalidArgs(param.getSendMonth())) {
            param.setSendMonth(DateUtil.getMonthString());
        }


        orderReadDao.beginPager(pageParam);
        List<SalvationObjectDTO> list = orderReadDao.getSupplyObjectList(param);


        return orderReadDao.endPager(list);
    }


    public Page<ProvertyObjectDTO> getExtProvertyObjectList(ProvertyObjectParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);
        param.setSystemTime(DateUtil.getMonthString());


        orderReadDao.beginPager(pageParam);
        List<ProvertyObjectDTO> list = orderReadDao.getExtProvertyObjectList(param);


        return orderReadDao.endPager(list);
    }


    public Page<SalvationFamilyDTO> getSalvationFamilyList4BatchStop(SalvationFamilyParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);


        orderReadDao.beginPager(pageParam);
        List<SalvationFamilyDTO> list = orderReadDao.getSalvationFamilyList4BatchStop(param);


        return orderReadDao.endPager(list);
    }


    public OrderEntity getOrderByFamilyIdAndCommitDate(String familyId, Date commitDate) {
        return orderReadDao.getOrderByFamilyIdAndCommitDate(familyId,commitDate);
    }


    public List<String> listRecheckOrderId(List<String> orderIds) {
        return orderReadDao.listRecheckOrderId(orderIds);
    }



    public Page queryAllInNoBank(SalvationObjectParam param, PageParam pageParam){
        orderReadDao.beginPager(pageParam);
        List<CustomFundDTO> fundPayEntityList = orderReadDao.queryAllInNoBank(param);
        fundPayEntityList.forEach(fundPayEntity->{
            //TaAreaPo taAreaPo4 = areaReadService.getAreaByCode(fundPayEntity.getAreaCode());
            String start = fundPayEntity.getStartMonth();

            if(Integer.parseInt(start) <Integer.parseInt(DateUtil.getMonthString())){
                start = DateUtil.getMonthString();
            }
            String end = DateUtil.getMonthString();
            int month = DateUtil.calDiffMonth(start,end);
            fundPayEntity.setMonth(month);


//                String[] temp = taAreaPo4.getNamePath().split("/");

//                fundPayEntity.setCommunity(taAreaPo4.getAreaName());
//                fundPayEntity.setTownship(temp[temp.length-2]);
//                fundPayEntity.setCounty(temp[temp.length-3]);
//                //fundPayEntity.setAreaCode(taAreaPo4.getAreaName());

            //fundPayEntity.setPayDate(fundPayEntity.getPayDate().substring(0, fundPayEntity.getPayDate().lastIndexOf("-")));
        });
        return orderReadDao.endPager(fundPayEntityList);
    }


    public List<CustomFundDTO> queryCustomByAllMem(SalvationObjectParam param){

        List<CustomFundDTO> fundPayEntityList = orderReadDao.queryCustomByAllMem(param);
        if(CollectionUtils.isEmpty(fundPayEntityList)){
            throw new BizException(FailureCode.ERR_10003);
        }
        StringBuffer ids = new StringBuffer("");
        fundPayEntityList.forEach(fundPayEntity->{
            ids.append(fundPayEntity.getId()).append(",");
        });


        String idCard = ids.deleteCharAt(ids.length()-1).toString();
        param.setIds(idCard.split(","));
        List<CustomFundDTO> timeList = orderReadDao.queryCustomByAllDate(param);

        Map<String, List<CustomFundDTO>> groupBy = timeList.stream().collect(Collectors.groupingBy(CustomFundDTO::getIdcard));
        fundPayEntityList.forEach(fundPayEntity->{
            String ic = fundPayEntity.getId();
            List<CustomFundDTO> customFundDTOS = groupBy.get(ic);
            if(CollectionUtils.isNotEmpty(customFundDTOS)){
                int month = 0;

                if(customFundDTOS.size() == 1){
                    String startMonth = customFundDTOS.get(0).getStartMonth();
                    String endMonth = customFundDTOS.get(0).getEndMonth();
                    if(Constant.MAX_YEAR.equals(customFundDTOS.get(0).getEndMonth())){
                        endMonth = param.getSendMonth() == null ? DateUtil.getMonthString() : param.getSendMonth();
                    }
                    month = DateUtil.calDiffMonth(startMonth,endMonth);
                    if(month < 0){ month = 0;}
                    fundPayEntity.setMonth(month);
                }else{
                    for(int i = 0; i < customFundDTOS.size(); i++){
                        String startMonth = customFundDTOS.get(i).getStartMonth();
                        String endMonth = customFundDTOS.get(i).getEndMonth();
                        if(Constant.MAX_YEAR.equals(customFundDTOS.get(i).getEndMonth())){
                            endMonth = param.getSendMonth() == null ? DateUtil.getMonthString() : param.getSendMonth();
                        }
                        int totle = DateUtil.calDiffMonth(startMonth,endMonth);
                        if(totle >= 0){
                            month = month+totle;
                        }
                    }
                }
                fundPayEntity.setMonth(month);
            }
        });
        return fundPayEntityList;
    }


    public MininumLivingApplyDTO getFinishedDetailById(String orderId) {
        MininumLivingApplyDTO applyDto = orderReadDao.getFinishedOrderDetailById(orderId);

        if (applyDto != null) {

            AreaHelper.AreaPo areaPo = areaHelper.getAreaByCode(applyDto.getAreaCode());
            applyDto.setAreaName(areaPo.getAreaName());
        }

        return applyDto;
    }


    public MininumLivingApplyDTO getDetailById(String id) {
        MininumLivingApplyDTO applyDto = orderReadDao.getOrderDetailById(id);


        if (applyDto != null) {
            AreaHelper.AreaPo areaPo = areaHelper.getAreaByCode(applyDto.getAreaCode());
            applyDto.setAreaName(areaPo.getAreaName());

//            if(!CommonUtil.invalidArgs(applyDto.getFileObjId())){
//                applyDto.setFileObjId(fileService.getFileUrl(applyDto.getFileObjId()));

        }

        return applyDto;
    }


    public int cntByBizState(String orderId, String preBizState){
        return orderReadDao.cntByBizState(orderId, preBizState);
    }


    public String getBizStateByBizStateRange(String orderId, String preBizState){
        return orderReadDao.getBizStateByBizStateRange(orderId, preBizState);
    }


    public Map getFamilyCountSummary(SalvationFamilyParam param,UserAccountVo accountVo) {
        Map familyCountSummary;

        logger.info("start setBaseParamValue");
        QueryParamUtil.setBaseParamValue(param,accountVo);
        logger.info("end setBaseParamValue");
        if(CommonUtil.invalidArgs(param.getSendMonth())){
            param.setSendMonth(DateUtil.getMonthString());
        }
        if (Constant.BusinessCode.DIBAO.equals(param.getBusinessType())) {

            logger.info("start getFamilyCountSummary");
            familyCountSummary = orderReadDao.getFamilyCountSummary(param);
        } else {

            logger.info("start getSupplyFamilyCountSummary");
            familyCountSummary = orderReadDao.getSupplyFamilyCountSummary(param);
        }

        logger.info("start getPauseFamilyCount");
        int count = orderReadDao.getPauseFamilyCount(param);
        familyCountSummary.put("pauseHouse", count);
        logger.info("end getFamilyCountSummary");
        return familyCountSummary;
    }


    public Map getObjectCountSummary(SalvationObjectParam param, UserAccountVo accountVo) {
        Map objectCountSummary;

        QueryParamUtil.setBaseParamValue(param,accountVo);
        if(CommonUtil.invalidArgs(param.getSendMonth())){
            param.setSendMonth(DateUtil.getMonthString());
        }
        if (Constant.BusinessCode.DIBAO.equals(param.getBusinessType())) {

            objectCountSummary = orderReadDao.getObjectCountSummary(param);
        } else {

            objectCountSummary = orderReadDao.getSupplyObjectCountSummary(param);
        }

        logger.info("start getPauseMemberCount");
        int count = orderReadDao.getPauseMemberCount(param);
        objectCountSummary.put("pauseHouse", count);
        return objectCountSummary;
    }


    public int getSaveMemberNumber(String orderId){
        return orderReadDao.getSaveMemberNumber(orderId);
    }



    public OrderEntity getLatestFinishedOrder(String idcard) {
        return orderReadDao.getLatestFinishedOrder(idcard);
    }


    public List<Map> countBacklog(BaseParam param) {
        return orderReadDao.countBacklog(param);
    }

    public List<Map> countMiniBacklog(BaseParam param) {
        return orderReadDao.countMiniBacklog(param);
    }


    public String getBizStateById(String id) {
        return orderReadDao.getBizStateById(id);
    }


    public String getStateById(String id) {
        return orderReadDao.getStateById(id);
    }


    public List<ExMemberExcelDto> exportExRescueFamilyList(SalvationObjectParam param){ return orderReadDao.exportExRescueFamilyList(param); }


    public List<ExMemberExcelNewDto> exportExRescueList(SalvationFamilyParam param){ return orderReadDao.exportExRescueList(param); }


    public List<ExMemberExcelDto> exportExRescueMemberList(SalvationObjectParam param){ return orderReadDao.exportExRescueMemberList(param); }


    public List<MiniMemberExcelDto> exportMiniRescueFamilyList(SalvationObjectParam param){ return orderReadDao.exportMiniRescueFamilyList(param);}


    public List<MiniMemberExcelNewDto> exportMiniRescueList(SalvationFamilyParam param){ return orderReadDao.exportMiniRescueList(param);}


    public List<MiniMemberExcDto> exportMiniRescueMemberList(SalvationObjectParam param){ return orderReadDao.exportMiniRescueMemberList(param);}


    public List<OrderEntity> listAnyTodoByIdCard(String idcard) {
        return orderReadDao.listAnyTodoByIdCard(idcard);
    }


    public List<OrderEntity> listAnyNotExpireOrderByIdCard(String idcard) {
        return orderReadDao.listAnyNotExpireOrderByIdCard(idcard);
    }


    public OrderEntity getOrderStateById(String orderId) {
        return orderReadDao.getOrderStateById(orderId);
    }


    public OrderSalaryDTO getSalaryInfo(String orderId){
        return orderReadDao.getSalaryInfo(orderId);
    }


    public OrderEntity getById(String orderId){
        return orderReadDao.getById(orderId);
    }

    public  List<OrderEntity> getByIdList(List<String> idList){
        return orderReadDao.getByIdList(idList);
    }


    public List<String> getExistNoFinishIdcard(List<String> idcardList){
        return orderReadDao.getExistNoFinishIdcard(idcardList);
    }


    public List<OrderFamilyDTO> getOrderFamilyByOrderIdList(List<String> orderIdList){
        return orderReadDao.getOrderFamilyByOrderIdList(orderIdList);
    }


    public List<ProResultDTO> getProResult(List<String> idList){
        return orderReadDao.getProResult(idList);
    }

    public List<CheckFamilyDTO> getCheckInfo(List<String> list){return orderReadDao.getCheckInfo(list);}

    public List<CheckFamilyDTO> getCheckInfoByHistory(List<String> list){return orderReadDao.getCheckInfoByHistory(list);}

    public List<QueryCheckDTO> selectCheckParam(List<String> list){return orderReadDao.selectCheckParam(list);}


    public int isCalSalary(String orderid){
        int rst = orderReadDao.selectIsCalSalary(orderid);
        if(rst < 1){
            throw new BizException("-1", "业务信息已被锁定，无法更新信息");
        }
        return  rst;
    }



    public OrderStateVerifyDTO getBizStateReportFile(String orderId){
        return orderReadDao.getBizStateReportFile(orderId);
    }


    public List<OrderStateVerifyDTO> getBizStateReportFileList(List<String> orderIdList){
        return orderReadDao.getBizStateReportFileList(orderIdList);
    }


    public List<OrderStateVerifyDTO> getBizStateReportFileNotice(List<String> batchNoList, String orderTableName){
        return orderReadDao.getBizStateReportFileNotice(batchNoList, orderTableName);
    }


    public String getOrderObjKey(String orderId){
        return orderReadDao.getOrderObjKey(orderId);
    }

    public List<String> cntFileObjId(List<String> orderId){
        return orderReadDao.cntFileObjId(orderId);
    }


    public Map<String,Object> getInhouseRatio(OrderListSearchParam param,UserAccountVo accountVo){
        QueryParamUtil.setBaseParamValue(param,accountVo);
        Map<String,Object> map = new HashMap<>();
        map.put("month", Calendar.getInstance().get(Calendar.MONTH)+1);

        int sum = orderReadDao.selectFinishOrderCurMonth(param);

        int count = orderReadDao.selectInhouseOrderCurMonth(param);
        int ratio = 0;
        if(sum!=0){
            ratio = new BigDecimal(count*100).divide(new BigDecimal(sum), 0,BigDecimal.ROUND_HALF_UP).intValue();;
        }
        map.put("sum",sum);
        map.put("count",count);
        map.put("ratio",ratio);
        return map;
    }


    public int isCanPrintNotice(String orderId){

        String bizState = orderReadDao.getBizStateById(orderId);
        if(!Constant.BizStateNew.APPROVE_REFUSE.equals(bizState)){
            throw  new BizException("-1","只有拒批的申请才能打印不予受理通知书");
        }
        return 1;
    }

    public NoticeDTO getNoticesInfo(String orderId,UserAccountVo userAccountVo){
          NoticeDTO noticeDTO = orderReadDao.selectNoticeInfo(orderId, userAccountVo.getParentId());
          return noticeDTO;
    }

    public String selectAgentIdCardById(String orderId){return orderReadDao.selectAgentIdCardById(orderId);}



    public OrderEntity selectInfoByIdCard(String idCard,String businessType){return orderReadDao.selectInfoByIdCard(idCard,businessType);}


    public List<OrderEntity> selectInfoByIdCards(List<String> idcardList,String businessType){return orderReadDao.selectInfoByIdCards(idcardList,businessType);}


    public OrderEntity selectInfoMinByIdCard(String idCard,String businessType){return orderReadDao.selectInfoMinByIdCard(idCard,businessType);}


    public List<OrderEntity> selectInfoMinByIdCards(List<String> idcardList,String businessType){return orderReadDao.selectInfoMinByIdCards(idcardList,businessType);}



    public String queryStateByFmIdcard(String idcard, String businessType, String areacode){
        return orderReadDao.queryStateByFmIdcard(idcard,businessType,areacode);
    }

    public String queryLowerStateByIdcard(String idcard, String areacode){
        return orderReadDao.queryLowerStateByIdcard(idcard,areacode);
    }

    public int selectOrderInCalculate(String orderId){
       return orderReadDao.selectOrderInCalculate(orderId);
    }


    public List<OrderListExcelDTO> exportListTown(OrderListSearchParam param){ return orderReadDao.exportListTown(param);}


    public List<OrderListExcelDTO> exportListCounty(OrderListSearchParam param){ return orderReadDao.exportListCounty(param);}


    public List<OrderListExcelExDTO> exportListExTown(OrderListSearchParam param){ return orderReadDao.exportListExTown(param);}


    public List<OrderListExcelExDTO> exportListExCounty(OrderListSearchParam param){ return orderReadDao.exportListExCounty(param);}

    public List<OrderListPendingExcelDTO> exportTownSalvation(OrderListSearchParam param){ return orderReadDao.exportTownSalvation(param);}

    public List<OrderListCPendingExcelDTO> exportCountySalvation(OrderListSearchParam param){ return orderReadDao.exportCountySalvation(param);}


    public String selectStandByFamilyId(String familyId){
        return orderReadDao.selectStandByFamilyId(familyId);
    }


    public List<PdfApproveDTO> findPdfInfo(String operateType, String businessType, String orderId, String yearMon, String areaCode){
        return orderReadDao.findPdfInfo(operateType,businessType,orderId,yearMon,areaCode);
    }


    public List<PdfApproveDetailDTO> findPdfInfoDetail(List<String> list){ return orderReadDao.findPdfInfoDetail(list); }



    public int getByIdCount(String id) {
        return orderReadDao.getByIdCount(id);
    }


    public MiniSalvationEFileYHDTO getMiniSalvationEFileYHDTOInfo(String orderId) {


        MiniSalvationEFileYHDTO miniSalvationEFileYHDTO = orderReadDao.getNewMiniSalvationEFileYHDTOInfo(orderId);

        MiniSalvationEFileYHDTO financial = orderReadDao.selectFinancialByOrderId(orderId);

        MiniSalvationEFileYHDTO checkinfo = orderReadDao.selectSalaryByOrderId(orderId);

        if(financial !=null ) {
            miniSalvationEFileYHDTO.setPO_wageIncome(financial.getPO_wageIncome());
            miniSalvationEFileYHDTO.setPO_wageComputer(financial.getPO_wageComputer());
            miniSalvationEFileYHDTO.setPO_businessIncome(financial.getPO_businessIncome());
            miniSalvationEFileYHDTO.setPO_businessComputer(financial.getPO_businessComputer());
            miniSalvationEFileYHDTO.setPO_propertyIncome(financial.getPO_propertyIncome());
            miniSalvationEFileYHDTO.setPO_propertyComputer(financial.getPO_propertyComputer());
            miniSalvationEFileYHDTO.setPO_transformIncome(financial.getPO_transformIncome());
            miniSalvationEFileYHDTO.setPO_transformComputer(financial.getPO_transformComputer());
            miniSalvationEFileYHDTO.setPO_otherIncome(financial.getPO_otherIncome());
            miniSalvationEFileYHDTO.setPO_otherInComputer(financial.getPO_otherInComputer());
            miniSalvationEFileYHDTO.setPO_incomeCount(financial.getPO_incomeCount());
            miniSalvationEFileYHDTO.setPO_illnessOutcome(financial.getPO_illnessOutcome());
            miniSalvationEFileYHDTO.setPO_illnessComputer(financial.getPO_illnessComputer());
            miniSalvationEFileYHDTO.setPO_educationOutcome(financial.getPO_educationOutcome());
            miniSalvationEFileYHDTO.setPO_educationComputer(financial.getPO_educationComputer());
            miniSalvationEFileYHDTO.setPO_otherOutcome(financial.getPO_otherOutcome());
            miniSalvationEFileYHDTO.setPO_otherOutComputer(financial.getPO_otherOutComputer());
            miniSalvationEFileYHDTO.setPO_income(financial.getPO_income());
            miniSalvationEFileYHDTO.setPO_carForInfo(financial.getPO_carForInfo());
        }

        if(checkinfo !=null ) {
            miniSalvationEFileYHDTO.setSalaryAmount(checkinfo.getSalaryAmount());
            miniSalvationEFileYHDTO.setPO_nurseSalary(checkinfo.getPO_nurseSalary());
            miniSalvationEFileYHDTO.setPO_livingSalary(checkinfo.getPO_livingSalary());
            miniSalvationEFileYHDTO.setLivingSalary(checkinfo.getLivingSalary());
            miniSalvationEFileYHDTO.setNurseSalary(checkinfo.getNurseSalary());
        }
        return miniSalvationEFileYHDTO;
    }


    public List<MiniSalvationEFileYHDTO.FamilyMemberInfo> getFamilyMemberInfo(String orderId, String tempType) {
        return orderReadDao.getFamilyMemberInfo(orderId, tempType);
    }


    public List<MiniSalvationEFileYHDTO.SupportPeopleInfo> getSupportPeopleInfo(String orderId) {
        return orderReadDao.getSupportPeopleInfo(orderId);
    }


    public List<MiniSalvationEFileYHDTO.SurveyFamilyMemberInfo> getSurveyFamilyMemberInfo(String orderId, String tempType) {
        return orderReadDao.getSurveyFamilyMemberInfo(orderId, tempType);
    }


    public List<MiniSalvationEFileYHDTO.SurveySupportPeopleInfo> getSurveySupportPeopleInfo(String orderId) {
        return orderReadDao.getSurveySupportPeopleInfo(orderId);
    }


    public List<MiniSalvationEFileYHDTO.ApplyFamilyBuildingsInfo> getApplyFamilyBuildingsInfo(String orderId) {
        return orderReadDao.getApplyFamilyBuildingsInfo(orderId);
    }

    public List<IntegrateCheckDTO> getIntegrateCheckInfo(List<String> orderIds){
        return orderReadDao.getIntegrateCheckInfo(orderIds);
    }

    public List<String> selectFamilyIdInBusiness(List<String> list){
        return orderReadDao.selectFamilyIdInBusiness(list);
    }

    public AuditConfirmListDTO selectAuditConfirmListDTO(String orderId){
        return orderReadDao.selectAuditConfirmListDTO(orderId);
    }

    public int selectOrderNoReason(String orderId){
        return orderReadDao.selectOrderNoReason(orderId);
    }




    public Page<SalvationObjectDTO> getInsuranceObj(SalvationObjectParam param, PageParam pageParam, UserAccountVo accountVo){

        QueryParamUtil.setBaseParamValue(param,accountVo);
        if (CommonUtil.invalidArgs(param.getSendMonth())) {
            param.setSendMonth(DateUtil.getMonthString());
        }
        param.setStartTime(new Date());
        param.setEndTime(new Date());

        // param.setAreaCode(accountVo.getAreaCode());

        orderReadDao.beginPager(pageParam);
        List<SalvationObjectDTO> list = orderReadDao.getInsuranceObj(param);


        return orderReadDao.endPager(list);
    }

    public OrderEntity selectLowerOrder(String orderId){
        return orderReadDao.selectLowerOrder(orderId);
    }


    public Page<SalvationObjectDTO> getSalvationObjectListForWxapp(SalvationObjectParam param, PageParam pageParam) {
        if(CommonUtil.invalidArgs(param.getSendMonth())){
            param.setSendMonth(DateUtil.getMonthString());
        }

        orderReadDao.beginPager(pageParam);
        List<SalvationObjectDTO> list = orderReadDao.getSalvationObjectList(param);


        return orderReadDao.endPager(list);
    }


    public SalvationFamilyDTO getOrderFamilyInfo(String orderId){
        return orderReadDao.getOrderFamilyInfo(orderId);
    }

    public MemberCardRtnDTO selectLowerOrderByCardId(String idcard){
        return orderReadDao.selectLowerOrderByCardId(idcard);
    }


    public OrderEntity getApplyTodoInfo(String idCard, String businessType, String areaCode) {
        return orderReadDao.getApplyTodoInfo(idCard, businessType, areaCode);
    }
}
